$(function(){
//nav效果
	$("#nav li:eq(0)").mouseenter(function(){
		$(this).children("span").stop(true).animate({"width":"80","left":"0"},500);
		$("#beauty").show().mouseover(function(){
			$(this).show();
		}).mouseout(function(){
			$(this).hide();
		});
		$(this).children("span").stop(true).animate({"width":"80","left":"0"},500);
	}).mouseleave(function(){
		$("#beauty").hide();
		$(this).children("span").animate({"width":"0","left":"40"},500);
	});
	$("#nav li:eq(1)").mouseenter(function(){
		$(this).children("span").stop(true).animate({"width":"80","left":"0"},500);
		$("#milk").show().mouseover(function(){
			$(this).show();
		}).mouseout(function(){
			$(this).hide();
		});
	}).mouseleave(function(){
		$("#milk").hide();
		$(this).children("span").animate({"width":"0","left":"40"},500);
	});
	$("#nav li:eq(2)").mouseenter(function(){
		$(this).children("span").stop(true).animate({"width":"80","left":"0"},500);
		$("#tax").show().mouseover(function(){
			$(this).show();
		}).mouseout(function(){
			$(this).hide();
		});
	}).mouseleave(function(){
		$("#tax").hide();
		$(this).children("span").animate({"width":"0","left":"40"},500);
	});
	$("#nav li:eq(3)").mouseenter(function(){
		$(this).children("span").stop(true).animate({"width":"80","left":"0"},500);
		$("#overseas").show().mouseover(function(){
			$(this).show();
		}).mouseout(function(){
			$(this).hide();
		});
	}).mouseleave(function(){
		$("#overseas").hide();
		$(this).children("span").animate({"width":"0","left":"40"},500);
	});

//nav 搜索框
   	$("#nav .text").focus(function(){
   		$(this).animate({"width":"168"},1000);
   	}).blur(function(){
   		$(this).animate({"width":"134"},1000);
   	});

//banner效果 
	var 
		n=-1,
		timer=null,
		onOff=true,
		bStop = true;
	move();
	timer=setInterval(move,3000);
	function move(){
		onOff=false;
		n++;
		if(n>=5){
			n=0;
		}
		fn();
	}
	function fn(){
		$(".img_list li:eq("+n+")").stop(true).animate({opacity:1},1000).siblings().animate({opacity:0},1000);
		$(".zs:eq("+n+")").animate({width:235},3000,function(){
			onOff=true;
			$(this).css({"width":"0"});
			if(!bStop) {
				bStop = true;
				move();
				timer=setInterval(move,3000);
			}
		});
	}
	
	$(".btn_right").click(function(){
		bStop = false;
		clearInterval(timer);
		$(".zs").stop(true).css('width', 0);
		move();
	});
	
	$(".btn_left").click(function(){
		n--;
		bStop = false;
		clearInterval(timer);
		$(".zs").stop(true).css('width', 0);
		if(n<0){
			n=4
		}
		fn();
	});
	
//倒计时
	function dao(day,name){
		var 
			dao_timer,
			iNew,
			iNow,
			t,
			str;
		dao_timer=setInterval(function(){
			iNow=new Date();
			iNew=new Date(day);
			t = Math.floor((iNew - iNow)/1000);
			str1 = Math.floor(t/86400)+'天'+Math.floor(t%86400/3600)+'时'+Math.floor(t%86400%3600/60)+'分'+t%60+'秒';
			$(name).text(str1);
			if(t<=0){
				clearInterval(dao_timer);
				$(name).text("活动已结束，请下次再来！");
			}
		},1000);
	}
	dao("Jun 17 2016 9:42:30",".dao1");
	dao("Jun 22 2016 10:00:00",".dao2");
	dao("Jun 24 2016 10:00:00",".dao3");
	dao("Jun 27 2016 10:00:00",".dao4");

	
//children效果
	$("#children .pic").mouseover(function(){
		$(this).children("div").show();
	}).mouseout(function(){
		$(this).children("div").hide();
	});
	
	$("#children span").each(function(){
		$("#children span").mouseover(function(){
			$(this).css({"background":"#fff"});
			$(this).siblings().css({"background":"#dfdfdf"});
			if($(this).index()==0){
				$("#children .hot").fadeIn();
				$("#children .tui").fadeOut();
			}else{
				$("#children .tui").fadeIn();
				$("#children .hot").fadeOut();
			}
		}).mouseout(function(){
			$(this).css({"background":"#fff"});
		});
	});

	$("#children li").mousemove(function(){
		$(this).children("a").hide().siblings().show();
	}).mouseout(function(){
		$(this).children("a").show().siblings().hide();
	});
	
//food效果
	$("#food .pic").mouseover(function(){
		$(this).children("div").show();
	}).mouseout(function(){
		$(this).children("div").hide();
	});
	
	$("#food span").each(function(){
		$("#food span").mouseover(function(){
			$(this).css({"background":"#fff"});
			$(this).siblings().css({"background":"#dfdfdf"});
			if($(this).index()==0){
				$("#food .hot").fadeIn();
				$("#food .tui").fadeOut();
			}else{
				$("#food .tui").fadeIn();
				$("#food .hot").fadeOut();
			}
		}).mouseout(function(){
			$(this).css({"background":"#fff"});
		});
	});

	$("#food li").mousemove(function(){
		$(this).children("a").hide().siblings().show();
	}).mouseout(function(){
		$(this).children("a").show().siblings().hide();
	});



//meili效果
	$("#meili .pic").mouseover(function(){
		$(this).children("div").show();
	}).mouseout(function(){
		$(this).children("div").hide();
	});
	
	$("#meili span").each(function(){
		$("#meili span").mouseover(function(){
			$(this).css({"background":"#fff"});
			$(this).siblings().css({"background":"#dfdfdf"});
			if($(this).index()==0){
				$("#meili .hot").fadeIn();
				$("#meili .tui").fadeOut();
			}else{
				$("#meili .tui").fadeIn();
				$("#meili .hot").fadeOut();
			}
		}).mouseout(function(){
			$(this).css({"background":"#fff"});
		});
	});

	$("#meili li").mousemove(function(){
		$(this).children("a").hide().siblings().show();
	}).mouseout(function(){
		$(this).children("a").show().siblings().hide();
	});



	//chose效果
	$("#chose li").mouseover(function(){
		$(this).css({"opacity":"0.7"});
	}).mouseout(function(){
		$(this).css({"opacity":"1"});
	});
	
	//floor效果
	$(window).scroll(function(){
		var 
			scrollT=document.documentElement.scrollTop||document.body.scrollTop;
		if(scrollT>=400){
			$("#floor").show();
			$("#include").css({"position":"fixed","left":"0","top":"0","display":"block"});
			
		}else{
			$("#floor").hide();
			$("#include").css({"position":"relative"});
		}
	});
	var onOff=true;
	$("#floor li").each(function(){
		$("#floor li").click(function(){
			$(this).children("a").find(".pic").hide().siblings().show();
			$(this).siblings().children("a").find(".pic").show().siblings().hide();
		});
	});

});
window.onload=function(){
	
	var 
		oNav=document.getElementById("nav"),
		oFloor=document.getElementById("floor"),
		aFloorLi=oFloor.getElementsByTagName("li"),
		onOff=true,
		timer1=null,
		arr_F=[],
	s=$(".side_scroll");
	for(var i=0;i<s.length;i++){
		arr_F.push(s[i].offsetTop);
	}
	
	for(var i=0;i<aFloorLi.length;i++){
		(function(i){
			aFloorLi[i].onclick=function(){
				if(onOff){
					onOff=false;
					timer1=setInterval(function(){
						var 
							scrollT=document.documentElement.scrollTop||document.body.scrollTop,
							s=i+1,
							speed=Math.round((arr_F[i]-90-scrollT)/10);
						document.documentElement.scrollTop=document.body.scrollTop=scrollT+speed;
						
						if(speed==0){
							clearInterval(timer1);
							onOff=true;
						}
					},30);
				}
			}
		})(i);
	}

//封装声明
function $1(obj){
	var firstChar=obj.charAt(0);
	if(firstChar=="#"){
		return document.getElementById(obj.substring(1));
	}else if(firstChar=="."){
		var aEls=document.getElementsByTagName("*");
		var arr=[];
		for(var i=0;i<aEls.length;i++){
			var arrclassName=aEls[i].className.split(" ");
			for(var j=0;j<arrclassName.length;j++){
				if(arrclassName[j]==obj.substring(1)){
					arr.push(aEls[i]);
					break;
				}
			}
		}
		return arr;
	}else{
		return document.getElementsByTagName(obj); 
	}
}
}
